import java.util.Scanner;

public class day230410 {
    // 查找两个字符串a,b中的最长公共子串

    // 动态规划
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();


        if (str1.length() > str2.length()) {
            String tmp = str2;
            str2 = str1;
            str1 = tmp;
        }

        char[] arr1 = str1.toCharArray();
        char[] arr2 = str2.toCharArray();
        int m = arr1.length;
        int n = arr2.length;

        // 多定义一行一列, 用来表示以第0个字符结尾的子串
        int[][] dp = new int[m + 1][n + 1];
        // 初始化
        dp[0][0] = 0;

        // 记录最长子串
        int start = 0;
        int maxLen = 0;

        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if (arr1[i - 1] == arr2[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    if (dp[i][j] > maxLen) {
                        // 更新最长子串
                        maxLen = dp[i][j];
                        start = i - maxLen;
                    }
                } else {
                    dp[i][j] = 0;
                }
            }
        }

        System.out.println(str1.substring(start, start + maxLen));
    }


    // 暴力破解
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();

        if (str1.length() < str2.length()) {
            String tmp = str1;
            str1 = str2;
            str2 = tmp;
        }

        // 若有多个，输出在较短串中最先出现的那个
        // str2 应该为较短的字符串

        StringBuilder ret = new StringBuilder();
        for (int i = 0; i < str2.length(); i++) {
            // 假设 str1 为  abcdef
            // str2 为  xasdcdefgh
            // 首先 abcdef 与 xasdcdefgh
            // 然后 abcdef 与 asdcdefgh
            // abcdef 与 sdcdefgh
            // abcdef 与 dcdefgh
            // abcdef 与 cdefgh

            StringBuilder tmp = func(str1, str2.substring(i));
            if (ret.length() < tmp.length()) {
                ret = tmp;
            }
        }

        System.out.println(ret);
    }

    public static StringBuilder func(String str1, String str2) {
        // 对比
        // 假设 str1 为  abcdef
        // str2 为  cdefgh
        // 首先 abcdef 与 cdefgh 配对
        // 然后 bcdef 与 cdefgh 配对
        // cdef 与 cdefgh 配对
        //

        StringBuilder sb = new StringBuilder();
        int j = 0;
        for (int i = 0; i < str1.length() ; i++) {
            StringBuilder tmp = new StringBuilder();
            int n = i;
            while (i < str1.length() && j < str2.length()
                    && str1.charAt(i) == str2.charAt(j)) {
                tmp.append(str1.charAt(i));
                i++;
                j++;
            }
            if (sb.length() < tmp.length()) {
                sb = tmp;
            }
            j = 0;
            i = n;
        }
        return sb;
    }


    // 汽水瓶
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int sum = 0;
            while (n >= 2) {
                int a = n / 3;
                n %= 3;
                sum += a;
                n += a;
                if (n == 2) {
                    n += 1;
                }
            }
            System.out.println(sum);
        }
    }
}
